﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
namespace Nirvana
{
    [Serializable]

    public sealed class CheckParticleSystem
    {
		[SerializeField]
		[Tooltip("The limit for max particle count.")]
		private int maxParticleLimit = -1;

		[SerializeField]
		[Tooltip("If the duration of the particle system exceeded limit, there can no turn on the prewarm.")]
		private float prewarmDurationLimit = -1f;

		[Tooltip("The scaling check mode.")]
		[EnumLabel]
		[SerializeField]
		private ScalingMode scalingMode;

		private enum ScalingMode
		{
			[EnumLabel("Not Check")]
			NotCheck=0,
            [EnumLabel("Hierarchy")]
            Hierarchy,
            [EnumLabel("Local")]
            Local,
            [EnumLabel("Shape")]
            Shape
        }


		public void CheckParitcle(AssetCheckReport report, ParticleSystem particle)
        {
			if (this.maxParticleLimit >= 0)
			{
				ParticleSystem.MainModule main = particle.main;
				if (main.maxParticles > this.maxParticleLimit)
				{
					report.ShowWarnInfo("The ParticleSystem <b><color=orange>{0}</color></b> max particle count is <b><color=orange>{1}</color></b>, is more than {2}.",
						particle.name,
						main.maxParticles,
						this.maxParticleLimit
					);
				}
			}
			if (this.prewarmDurationLimit >= 0f)
			{
				ParticleSystem.MainModule main = particle.main;
				if (main.prewarm && main.duration > this.prewarmDurationLimit)
				{
					report.ShowWarnInfo("The ParticleSystem <b><color=orange>{0}</color></b> can not use prewarm.",particle.name);
				}
			}
			if (this.scalingMode != ScalingMode.NotCheck && particle.main.scalingMode == ParticleSystemScalingMode.Local)
			{
                report.ShowWarnInfo("The ParticleSystem <b><color=orange>{0}</color></b> can not use local scaling mode.", particle.name);
            }

            if (this.scalingMode == ScalingMode.Hierarchy) 
            {
                if(particle.main.scalingMode != ParticleSystemScalingMode.Hierarchy)
                {
                    report.ShowWarnInfo("The ParticleSystem <b><color=orange>{0}</color></b> can not use Hierarchy scaling mode.", particle.name);
                }
            }
            else if (this.scalingMode == ScalingMode.Local)
            {
                if (particle.main.scalingMode != ParticleSystemScalingMode.Local)
                {
                    report.ShowWarnInfo("The ParticleSystem <b><color=orange>{0}</color></b> can not use Local scaling mode.", particle.name);
                }
            }
            else if (this.scalingMode == ScalingMode.Shape)
            {
                if (particle.main.scalingMode != ParticleSystemScalingMode.Shape)
                {
                    report.ShowWarnInfo("The ParticleSystem <b><color=orange>{0}</color></b> can not use Shape scaling mode.", particle.name);
                }
            }

		}
	}
}
